package com.moss.cloud.common.sms.realize;

import com.moss.cloud.common.sms.model.SmsModel;
import com.moss.cloud.common.sms.operation.SmsOperation;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * 腾讯云存储实现
 *
 * @author 瑾年
 * @date 2023年4月19日
 */
@Slf4j
public class TencentSms implements SmsOperation {

    @Override
    @SneakyThrows
    public void sendSms(SmsModel smsModel) {
        Credential cred = new Credential(smsModel.getSmsConfig().getSecretId(), smsModel.getSmsConfig().getSecretKey());
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint(smsModel.getSmsConfig().getEndpoint());
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        SmsClient client = new SmsClient(cred, "", clientProfile);
        SendSmsRequest sendSmsRequest = new SendSmsRequest();
        sendSmsRequest.setSmsSdkAppid(smsModel.getSmsConfig().getAppId());
        sendSmsRequest.setSign(smsModel.getSign());
        sendSmsRequest.setPhoneNumberSet(smsModel.getPhoneNumbers());
        sendSmsRequest.setTemplateID(smsModel.getTemplateID());
        sendSmsRequest.setTemplateParamSet(smsModel.getTemplateParams());
        SendSmsResponse sendSmsResponse = client.SendSms(sendSmsRequest);
        log.info("腾讯云发送短信成功-服务端响应:{}",SendSmsResponse.toJsonString(sendSmsResponse));
    }
}
